<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript" src="${staticPath}/static/ckeditor4.10/ckeditor.js"></script>
<style>
    p img {
        width: auto;
        height: auto;
        max-width: 100%;
    }
</style>
<script type="text/javascript">
    var workSummaryDataGrid;
    $(function() {
        workSummaryDataGrid = $('#workSummaryDataGrid').datagrid({
            url : '${path}/workSummary/dataGrid?userid=<shiro:principal property = "id"/>',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                width : '300',
                title : '标题',
                field : 'name'
            },


                {
                width : '100',
                title : '类型',
                field : 'type',
                    formatter:function (value,row,index) {
                    if(value==0){
                        return "日总结"
                    }
                    if(value==1){
                        return "周总结"
                    }
                    if(value==2){
                        return "月总结"
                    }
                    if(value==3){
                        return "季度总结"
                    }
                    if(value==4){
                        return "年度总结"
                    }
                }
            }, {
                    width : '100',
                    title : '状态',
                    field : 'status',
                    formatter:function (value,row,index) {
                       if(value==1){
                           return "正常"
                       }
                       return "作废"
                    }
                },
                {
                width : '100',
                title : '创建时间',
                field : 'operateTime',
                    formatter:function (value,row,index) {
                    return datetime2Str(value);
                }
            },
                {
                width : '100',
                title : '附件',
                field : 'attachIds',
                    formatter:function (value,row,index) {
                       if(isNull(value)){
                           return ""
                       }else{
                           return "有"
                       }
                    }
            },
            ]],
            frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    if(row.status==1){
                        str += $.formatString('<a href="javascript:void(0)" class="workSummary-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editworkSummaryFun(\'{0}\');" >编辑</a>', row.id);
                        str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    }
                    str += $.formatString('<a href="javascript:void(0)" class="workSummary-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteworkSummaryFun(\'{0}\',\'{1}\');" >删除</a>', row.id,row.status);
                      str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="workSummary-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-magnifying-glass\'" onclick="viewworkSummaryFun(\'{0}\');" >查看</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.workSummary-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.workSummary-easyui-linkbutton-del').linkbutton({text:'删除'});
                $('.workSummary-easyui-linkbutton-view').linkbutton({text:'查看'});
            },
            toolbar : '#workSummaryToolbar'
        });
    });

    function addworkSummaryFun() {
        parent.$.modalDialog({
            title : '添加',
            width : '80%',
            height : '80%',
            href : '${path}/workSummary/addPage',
            buttons : [ {
                text : '保存',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = workSummaryDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#workSummaryAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function editworkSummaryFun(id) {
        if (id == undefined) {
            var rows = workSummaryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            workSummaryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : '80%',
            height : '80%',
            href : '${path}/workSummary/editPage/' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = workSummaryDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#workSummaryEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function deleteworkSummaryFun(id,status) {
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = workSummaryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            workSummaryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                var url='${path}/workSummary/cancel?id='+id+"&status=-1";
                if(status==-1){
                    url="${path}/workSummary/delete/"+id;
                }
                $.post(url, {}
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        workSummaryDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
     function viewworkSummaryFun(id) {
        if (id == undefined) {
            var rows =  workSummaryDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
             workSummaryDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '查看',
            width : '80%',
            height : '80%',
            href : '${path}/workSummary/viewPage/' + id,
        });
    }
    function searchworkSummaryFun() {
    	workSummaryDataGrid.datagrid('load', $.serializeObject($('#searchworkSummaryForm')));
    }
    function cleanworkSummaryFun() {
        document.getElementById('searchworkSummaryForm').reset();
       workSummaryDataGrid.datagrid('load', {});
    }

    function toggleCalendarWorkSummary(){
        var opts = {
            title : '工作总结-日历模式',
            border : false,
            closable : true,
            fit : true,
            iconCls : 'fi-calendar',
            href:'${ctxPath}/workSummary/manager2'
        };
        addTab(opts);
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="workSummaryDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="workSummaryToolbar" style="display: none;">
    <form id="searchworkSummaryForm">
        <table>
            <tr>
                <td>标题</td>
                <td>
                    <input name="name"   type="text" placeholder="请输入标题" class="easyui-text  span2" >
                </td>
                <td>日期</td>
                <td>
                <td>
                    <input type="text" name="saveDateStart" class="easyui-text" onclick="WdatePicker()">~
                    <input type="text" name="saveDateEnd" class="easyui-text" onclick="WdatePicker()">
                </td>
                <td>
                    状态
                </td>
                <td>
                    <select name="status" class="easyui-text">
                        <option value="">--- 请选择 ---</option>
                        <option value="1">正常</option>
                        <option value="-1">作废</option>
                    </select>
                </td>
                <td>
                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchworkSummaryFun();">查询</a>
                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanworkSummaryFun();">清空</a>
                    <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-calendar',plain:true" onclick="toggleCalendarWorkSummary();">日历模式</a>
                </td></tr>

        </table>
    </form>
    <a onclick="addworkSummaryFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>
